package com.scalar.chiptrack.finance.openpo.actioncommands;

import com.scalar.chiptrack.ChipTrackExtendedAction;
import com.scalar.chiptrack.users.ErrorReport;
import com.scalar.chiptrack.utils.Logger;
import com.scalar.chiptrack.finance.openpo.forms.PurchaseOrderForm;
import com.scalar.chiptrack.finance.openpo.dao.PurchaseOrderDAO;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

/**
 * Created by KumaraSwamy.
 * Date: Mar 24, 2005
 * Time: 3:01:55 PM
 * To Create New Package Type
 */

public class PurchaseOrderLoadPackageTypeCommand extends ChipTrackExtendedAction
{

    public ActionForward executeRequest( ActionMapping mapping,
                                         ActionForm form,
                                         HttpServletRequest request,
                                         HttpServletResponse response ) throws Exception
    {

        HashMap errors              = ( HashMap ) request.getAttribute( ERROR_MESSAGES );
        HashMap info                = ( HashMap ) request.getAttribute( INFO_MESSAGES );
        PurchaseOrderForm purchaseOrderForm = ( PurchaseOrderForm ) form;
		String actionForward 		= "Search";
        HttpSession mSession 		= request.getSession();

		try
        {
            request.setAttribute( "packageTypeList", PurchaseOrderDAO.loadPackTypeList() );

            actionForward = "purchaseOrderAddNewPackageType";
       	}
        catch ( Exception e )
        {
            Logger.error( ERRROR_LOADING_PACKAGE_TYPE_IN_PURCHASE_ORDER_LINE_ITEM, e );
            errors.put( ERROR_INTERNAL_SERVER_ERROR, ERRROR_LOADING_PACKAGE_TYPE_IN_PURCHASE_ORDER_LINE_ITEM );
			mSession.setAttribute( ERROR_REPORT_OBJECT, new ErrorReport( ERRROR_LOADING_PACKAGE_TYPE_IN_PURCHASE_ORDER_LINE_ITEM, e ) );
            actionForward = "load";
        }

		request.setAttribute( ERROR_MESSAGES, errors );
		request.setAttribute( INFO_MESSAGES, info );
		return mapping.findForward( actionForward );
    }
}

